home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2001 February / Internet Magazine February 2001.iso / mac / SOFTWARE / MAC / UTILITIES / NETFINDER / NETFINDER.HQX / NetFinder v2.2b5 / Scripts / Support - Lookup Domain / oD
Encoding:
Text File  |  2000-09-05  |  1.5 KB  |  70 lines

  1. /* 
  2.     Sample ICI script for NetFinder.
  3.     
  4.     This script Resolves Domain Names.
  5.     
  6.     The purpose of this script is for technical support when things are not
  7.     working...eg DNS not setup properly.
  8.     You can also use it for other purposes.
  9.     
  10.     NOTES:
  11.     o Full ICI programming syntax can be obtained from
  12.       <http://www.zeta.org.au/~atrn/ici/documentation.html>
  13.     
  14.     (c) Copyright 2000 Peter Li.
  15.  */
  16.  
  17.  
  18. /* define a few variables */
  19. auto TIMEOUT = 3;
  20. auto query = "";
  21. auto name = "";
  22.  
  23. try {
  24.     
  25.     /* prompt the user for input. */
  26.     
  27.     if (MICI.Ask("Enter a name to resolve: eg ╥ftp.cdrom.com╙ or ╥203.14.50.123╙",
  28.                  "" /* inDefaultAnswer */,
  29.                  &query) == 0)
  30.     {
  31.         /* if user didnt cancel, continue. Else do nothing. */
  32.         
  33.         // remove any leading and trailing spaces...
  34.         query = query ~~ # *([^ ]*) *#;
  35.         
  36.         if (query ~ #[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+#)
  37.         {
  38.             // user typed in a dot IP address so resolve it to the english name...
  39.             if (NFAddressToString(NFStringToAddress(query, TIMEOUT), &name, TIMEOUT) != 0)
  40.                 name = "unresolved address";
  41.         }
  42.         else
  43.         {
  44.             // user typed in an english name address so resolve it to a dot IP address...
  45.             auto    ip = 0;
  46.             
  47.             ip = NFStringToAddress(query, TIMEOUT);
  48.             
  49.             if (ip != 0)
  50.             {
  51.                 name = sprintf("%d.%d.%d.%d", 
  52.                                 (ip >> 24) & 0xFF,
  53.                                 (ip >> 16) & 0xFF,
  54.                                 (ip >> 8) & 0xFF,
  55.                                 (ip >> 0) & 0xFF
  56.                                 );
  57.             }
  58.             else
  59.                 name = "unresolved address";
  60.         }
  61.             
  62.         printf(    "\n"
  63.                 "Your  Query: %s\n"
  64.                 "Resolves To: %s\n\n", query, name);
  65.     }
  66. } onerror {
  67.     printf("'iciMICI.so' module is missing.\n");
  68. }
  69.  
  70.